

from Reg import *
from condition_c import *

RegKeyword("False")
RegKeyword("None")
RegKeyword("True")
RegKeyword("as")
RegKeyword("assert")
RegKeyword("break")
RegKeyword("class")
RegKeyword("continue")
RegKeyword("def")
RegKeyword("del")
RegKeyword("elif")
RegKeyword("else")
RegKeyword("except")
RegKeyword("finally")
RegKeyword("for")
RegKeyword("from")
RegKeyword("global")
RegKeyword("if")
RegKeyword("import")
RegKeyword("lambda")
RegKeyword("nonlocal")
RegKeyword("pass")
RegKeyword("raise")
RegKeyword("return")
RegKeyword("try")
RegKeyword("while")
RegKeyword("with")
RegKeyword("yield")


RegSymbol("and", "operator_and")
RegSymbol("or", "operator_or")
RegSymbol("not", "operator_not")
RegSymbol("in", "operator_in")
RegSymbol("is", "operator_is")



RegSymbol("**=", "operator_exponent_assign")
RegSymbol("//=", "operator_floor_division_assign")

RegSymbol("//", "operator_floor_division")
RegSymbol("**", "operator_exponent")




@RegParser(id="string_python", condition=is_python_string)
def string_python(content, offset):
    pre = offset

    ct = content[offset: offset+1]

    offset += 1
    while offset >= 0 and offset < len(content):
        c = content[offset: offset+1]
        offset += 1
        if c == ct:
            break
        elif c == '\\':
            offset += 1
        
    return (True, content[pre: offset], offset, "tok_string")

@RegParser(id="line_comment_py", condition=is_python_line_comment)
def line_comment_py(content, offset):
    pre = offset

    offset += 1
    while offset >= 0 and offset < len(content):
        if content[offset: offset+1] in ["\r", "\n"]:
            break
        if content[offset: offset+1] == "\\":
            offset += 1
        offset += 1

    return (True, content[pre: offset], offset, "tok_line_comment" )

@RegParser(id="block_string_py", condition=is_python_block_string)
def block_string_py(content, offset):
    pre = offset

    tmp = content[offset: offset+3]
    offset += 3
    while offset >= 0 and offset < len(content):
        if tmp == content[offset: offset+3]:
            break
        offset += 1
    offset += 3

    return (True, content[pre: offset], offset, "tok_block_string" )

@RegParser(id="f_string_py", condition=is_python_f_string)
def f_string_py(content, offset):
    pre = offset

    tmp = content[offset+1: offset+4]
    offset += 4
    while offset >= 0 and offset < len(content):
        if tmp == content[offset: offset+3]:
            break
        offset += 1
    offset += 3

    return (True, content[pre: offset], offset, "tok_f_string" )

    